/**
 * Created by Bill.li on 2016/1/22.
 */

$(document).ready(function(){
    $('.tab-li li').each(function(i){
        $(this).on('click',function(){
            $(this).addClass('active')
            $(this).siblings().removeClass('active')
            $('.sj-main .sj-0').eq(i).removeClass('none')
            $('.sj-main .sj-0').eq(i).siblings().addClass('none');
            var tabName=$(this).attr("tabName");
            //afterClickTab(tabName);
            getPipeLine("pipeLineUl");//获取管道列表

            $("form[name=queryForm]").validationEngine('attach',{
                promptPosition:'bottomLeft'
            });//初始化查询条件的验证




        });
    });
});


function convertStr(data){
    if (data == "" || data == null || data== undefined) {
        return "-";
    } else {
       return data;
    }
}


/*展示编辑标签页*/
function showUpdataPage(){
$(".edit0").live(function(){
    $("#xgsb").remove("none");
    $("#xgsb").show();
})
/*

function afterClickTrackPointTab(){
    getTrackPointList();//获取list列表
}
/!*导出excl*!/
function getTrackPointList(){
    var data_=$("#equipmentInfoForm").serializeFormJSON();
    var p=json2UrlParam(data_);
}
/!*条件查询*!/
function queryEquipmentInfo(){
    var code=$("#equipmentInfoQueryForm").validationEngine("validate");//验证表单
    if(!code){
        return;
    }
    var data=$("#equipmentInfoQueryForm").serializeFormJSON();/!*序列化json,自动获取参数*!/
    $("#equipmentInfo").selectDataAfterSetParm(data);/!*查询数据设置参数*!/
}
/!*删除*!/
function delEquipmentInfo(id){
    if(isEmpty(id)){
        attr("没有选择项!");
        return;
    }
    if(!confirm("是否确定删除!")){
        return;
    }
    $().invoke(
        p_path+"eqpt/delEquipmentInfo.json",{"id":id},[function(m,r){
            if(r=="success"){
                $("equipmentInfo").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )
}
/!*列表数据*!/
function getEquipmentInfo(){
    var cor=[{title:"设备编号",name:"customNumber",width:"10%",align:"center"},
            {title:"型号",name:"modelNumber",width:"10%",align:"center"},
            {title:"唯一识别码",name:"uniqueCide",width:"20%",align:"center"},
            {title:"购买时间",name:"buyDate",width:"10%",align:"center"},
            {title:"状态",name:"state",width:"10%",align:"center"},
            {title:"编辑 删除",name:"",width:"5%",align:"center",format:dataDeatilTrackPoint}]
    $("#trackPoint").initTable({
            url: p_path + "/eqpt/getEquipmentInfo.json",
            columnData: col,
            doubleRowMode:true,
            isrowClick:true,
            maxHeightMode:true,
            rowClickMethod:pipeTrackPointRowClick,
            selectDataNow:true
    });
}

function equipmentInfoCilck(data,obj,orderNum){
    try{
        var eventTarget_= event.target || event.srcElement;
        if (eventTarget_ != null && eventTarget_ != document&& eventTarget_.tagName=="EM") {
            if ($(eventTarget_).hasClass("delet2")) {
                return;
            }
        }
    } catch (e) {
        console.log(e)
    }

    var t=$("#trackPoint"+orderNum,$("#trackPoint"));
    $("td",t).html(showTrackPointUl(data));
    t.fadeToggle();
    return false;

}





/!*新增*!/
function  addEquipmentInfo(data){
    $().invoke(
        p_path+"eqpt/addEquipmentInfo.json",{"customNumber":customNumber,"modelNumber":modelNumber,"uniqueCide":uniqueCide,"buyDate":buyDate,"state":state,"updateRemark":updateRemark},[function(m,r){
            if(r=="success"){
                $("equipmentInfo").refresh();
            }
        },function(m,r){
            alert(r);
        }]

    )
}

/!*编辑更新*!/
function  updateEquipmentInfo(id){
    $("#submitUpdata").invoke(
        p_path+"eqpt/updateEquipmentInfo.json",{"id":id,"customNumber":customNumber,"modelNumber":modelNumber,"uniqueCide":uniqueCide,"buyDate":buyDate,"state":state,"updateRemark":updateRemark},[function(m,r){
            if(r=="success"){
                $("equipmentInfo").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )

}
/!*导出*!/
function exportEquipmentInfo(){
    //var juliStart=nvl_($("#juliStart").val());
    //var juliEnd=nvl_($("#juliEnd").val());
    var data_=$("#equipmentInfoForm").serializeFormJSON();
    var p=json2UrlParam(data_);
    location.href=p_path+"/eqpt/exportEquipmentInfo.json?"+p;
}

*/











/*内部借用*/
function afterClickEmpUseTab(){
    getEmpUseList();//获取list列表
}
/*导出excl*/
function getEmpUse(){
    var data_=$("#empUseForm").serializeFormJSON();
    var p=json2UrlParam(data_);
}
/*条件查询*/
function queryEmpUse(){
    var code=$("#empUseForm").validationEngine("validate");//验证表单
    if(!code){
        return;
    }
    var date=$("#empUseForm").serializeFormJSON();/*序列化json*/
    $("#equipmentInfo").selectDataAfterSetParm(data_);/*查询数据设置参数*/
}
/*删除*/
function delEmpUse(id,idList){
    if(isEmpty(id)){
        attr("没有选择项!");
        return;
    }
    if(!confirm("是否确定删除!")){
        return;
    }
    $().invoke(                                                       /*多个删除使用idList传值*/
        p_path+"eqpt/delEmpUse.json",{"id":id,"idList":idList},[function(m,r){
            if(r=="success"){
                $("empUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )
}
/*列表数据*/
function getEmpUse(){
    var col=[{title:"设备编号",name:"customNumber",width:"10%",align:"center"},
            {title:"型号",name:"modelNumber",width:"10%",align:"center"},
            {title:"使用单位",name:"modelNumber",width:"10%",align:"center"},
            {title:"领用人",name:"modelNumber",width:"10%",align:"center"},
            {title:"联系电话",name:"modelNumber",width:"10%",align:"center"},
            {title:"领用日期",name:"modelNumber",width:"10%",align:"center"},
            {title:"归还日期",name:"modelNumber",width:"10%",align:"center"},
            {title:"有效时间",name:"modelNumber",width:"10%",align:"center"},
            {title:"编辑 删除",name:"",width:"5%",align:"center",format:dataDeatilTrackPoint}]
    $("#EmpUse").initTable({
        url: p_path + "/eqpt/getEmpUse.json",
        columnData: col,
        doubleRowMode:true,
        isrowClick:true,
        maxHeightMode:true,
        rowClickMethod:pipeTrackPointRowClick,
        selectDataNow:true
    });
}

function empUseCilck(data,obj,orderNum){
    try{
        var eventTarget_= event.target || event.srcElement;
        if (eventTarget_ != null && eventTarget_ != document&& eventTarget_.tagName=="EM") {
            if ($(eventTarget_).hasClass("delet2")) {
                return;
            }
        }
    } catch (e) {
        console.log(e)
    }

    var t=$("#empUse"+orderNum,$("#empUse"));
    $("td",t).html(showEmpUseUl(data));
    t.fadeToggle();
    return false;

}

/*新增*/
function  addEmpUse(data){
    $().invoke(
        p_path+"eqpt/addEmpUse.json",{"userId":userId,"startDate":startDate,"endDate":endDate,"updateRemark":updateRemark},[function(m,r){
            if(r=="success"){
                $("empUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]

    )
}

/*编辑更新*/
function  updateEmpUse(id){
    $().invoke(
        p_path+"eqpt/updateEmpUse.json",{"id":id,"userId":userId,"startDate":startDate,"endDate":endDate,"updateRemark":updateRemark},[function(m,r){
            if(r=="success"){
                $("empUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )
}












/*外部借用*/
function afterClickExtemalUseTab(){
    getExtemalUseList();//获取list列表
}
/*条件查询*/
function queryExtemalUse(){
    var code=$("#extemalUseForm").validationEngine("validate");//验证表单
    if(!code){
        return;
    }
    var date=$("#extemalUseForm").serializeFormJSON();/*序列化json*/
    $("#extemalUse").selectDataAfterSetParm(data_);/*查询数据设置参数*/
}
/*删除*/
function delExtemalUse(id,idList){
    if(isEmpty(id)){
        attr("没有选择项!");
        return;
    }
    if(!confirm("是否确定删除!")){
        return;
    }
    $().invoke(                                                       /*多个删除使用idList传值*/
        p_path+"eqpt/delExtemalUse.json",{"id":id,"idList":idList},[function(m,r){
            if(r=="success"){
                $("ExtemalUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]
    )
}
/*列表数据*/
function getExtemalUse(){
    var col=[{title:"设备编号",name:"customNumber",width:"10%",align:"center"},
        {title:"型号",name:"modelNumber",width:"10%",align:"center"},
        {title:"使用单位",name:"modelNumber",width:"10%",align:"center"},
        {title:"领用人",name:"modelNumber",width:"10%",align:"center"},
        {title:"联系电话",name:"modelNumber",width:"10%",align:"center"},
        {title:"领用日期",name:"modelNumber",width:"10%",align:"center"},
        {title:"归还日期",name:"modelNumber",width:"10%",align:"center"},
        {title:"有效时间",name:"modelNumber",width:"10%",align:"center"},
        {title:"编辑 删除",name:"",width:"5%",align:"center",format:dataDeatilTrackPoint}]
    $("#extemalUse").initTable({
        url: p_path + "/eqpt/getExtemalUse.json",
        columnData: col,
        doubleRowMode:true,
        isrowClick:true,
        maxHeightMode:true,
        rowClickMethod:pipeTrackPointRowClick,
        selectDataNow:true
    });
}

function extemalUseCilck(data,obj,orderNum){
    try{
        var eventTarget_= event.target || event.srcElement;
        if (eventTarget_ != null && eventTarget_ != document&& eventTarget_.tagName=="EM") {
            if ($(eventTarget_).hasClass("delet2")) {
                return;
            }
        }
    } catch (e) {
        console.log(e)
    }

    var t=$("#ExtemalUse"+orderNum,$("#ExtemalUse"));
    $("td",t).html(showTrackPointUl(data));
    t.fadeToggle();
    return false;

}

/*新增*/
function  addEquipmentInfo(adddata){
    $().invoke(
        p_path+"eqpt/addExtemalUse.json",{"userId":userId,"startDate":startDate,"endDate":endDate,"updateRemark":updateRemark},[function(m,r){
            if(r=="success"){
                $("ExtemalUse").refresh();
            }
        },function(m,r){
            alert(r);
        }]

    )
}

/*编辑更新*/
function  updateExtemalUse(id) {
    $().invoke(
        p_path + "eqpt/updateExtemalUse.json", {
            "id": id,
            "userId": userId,
            "startDate": startDate,
            "endDate": endDate,
            "updateRemark": updateRemark
        }, [function (m, r) {
            if (r == "success") {
                $("ExtemalUse").refresh();
            }
        }, function (m, r) {
            alert(r);
        }]
    )
}}

/*function dataDeatil(json){
    var h="<li class=\"w12-4-3-1 no-right\" style='list-style: none;'>" +
        "<em class=\"xq-icon\"></em>" +
        "<em onclick=delCrossOver('"+json.id+"') class=\"delet2\"></em></li>";
    return h;
}*/





